<template>
  <view v-if="isShow" class="wx-bg" @click="toWxAPP"></view>
</template>

<script setup>
  import { userStore } from '@/stores'
  import { computed } from 'vue'

  // 判断该商户是否展示
  const userInfoStore = userStore()
  const isShow = computed(() => {
    return userInfoStore.indexInfo.bjmBanner
  })

  const toWxAPP = () => {
    // #ifdef APP-PLUS
    plus.share.getServices(
      function (res) {
        var sweixin = null
        for (var i = 0; i < res.length; i++) {
          var t = res[i]
          if (t.id == 'weixin') {
            sweixin = t
          }
        }
        if (sweixin) {
          sweixin.launchMiniProgram({
            id: 'gh_ea568d0193c1', // 小程序原始id
            type: 0, // 0-正式版； 1-测试版； 2-体验版。 默认值为0
            path: '/pages/index/index?scene=channel%3A204',
          })
        } else {
          plus.nativeUI.alert('当前环境不支持微信操作!')
        }
      },
      function (res) {
        console.log(JSON.stringify(res))
      },
    )
    // #endif
  }
</script>

<style lang="less" scoped>
  .wx-bg {
    background-image: url('~@/static/images/bjm_wxapp.png');
    height: 210rpx;
    width: 700rpx;
    margin: 0 auto 48rpx;
    margin-top: 0;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: left top;
  }
</style>
